package cn.udesk.web.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.udesk.core.dto.BootTablePage;
import cn.udesk.core.mapper.KTransMonitorDao;
import cn.udesk.core.model.KTransMonitor;

@Service
public class TransMonitorService {

  @Autowired
  private KTransMonitorDao kTransMonitorDao;

  /**
   * @Title getList
   * @Description 获取分页列表
   * @param start 起始行数
   * @param size 每页数据条数
   * @param uId 用户ID
   * @return
   * @return BootTablePage
   */
  public BootTablePage getList(Integer start, Integer size) {
    KTransMonitor template = new KTransMonitor();
    List<KTransMonitor> kTransMonitorList = kTransMonitorDao.template(template, start, size);
    Long allCount = kTransMonitorDao.templateCount(template);
    BootTablePage bootTablePage = new BootTablePage();
    bootTablePage.setRows(kTransMonitorList);
    bootTablePage.setTotal(allCount);
    return bootTablePage;
  }

  /**
   * @Title getList
   * @Description 获取不分页列表
   * @param start 起始行数
   * @param size 每页数据条数
   * @param uId 用户ID
   * @return
   * @return BootTablePage
   */
  public BootTablePage getList() {
    KTransMonitor template = new KTransMonitor();
    template.setMonitorStatus(1);
    List<KTransMonitor> kTransMonitorList = kTransMonitorDao.template(template);
    Collections.sort(kTransMonitorList);
    List<KTransMonitor> newKTransMonitorList = new ArrayList<KTransMonitor>();
    BootTablePage bootTablePage = new BootTablePage();
    bootTablePage.setRows(newKTransMonitorList);
    bootTablePage.setTotal(5);
    return bootTablePage;
  }

  /**
   * @Title getAllMonitorTrans
   * @Description 获取全部被监控的转换
   * @param uId 用户ID
   * @return
   * @return Integer
   */
  public Integer getAllMonitorTrans() {
    KTransMonitor template = new KTransMonitor();
    List<KTransMonitor> kTransMonitorList = kTransMonitorDao.template(template);
    return kTransMonitorList.size();
  }

  /**
   * @Title getAllSuccess
   * @Description 获取所有转换执行成功的次数的和
   * @param uId 用户ID
   * @return
   * @return Integer
   */
  public Integer getAllSuccess() {
    KTransMonitor template = new KTransMonitor();
    List<KTransMonitor> kTransMonitorList = kTransMonitorDao.template(template);
    Integer allSuccess = 0;
    for (KTransMonitor KTransMonitor : kTransMonitorList) {
      allSuccess += KTransMonitor.getMonitorSuccess();
    }
    return allSuccess;
  }

  /**
   * @Title getAllFail
   * @Description 获取所有转换执行失败的次数的和
   * @param uId 用户ID
   * @return
   * @return Integer
   */
  public Integer getAllFail() {
    KTransMonitor template = new KTransMonitor();
    List<KTransMonitor> kTransMonitorList = kTransMonitorDao.template(template);
    Integer allSuccess = 0;
    for (KTransMonitor KTransMonitor : kTransMonitorList) {
      allSuccess += KTransMonitor.getMonitorFail();
    }
    return allSuccess;
  }

}
